#{extends 'main.html' /}
<div>
    <ul>
        <li>
            <a href="">个人资料</a>
        </li>
        <li>
            <a href="">修改密码</a>
        </li>
        <li>
            <a href="">修改头像</a>
        </li>
        <li>
            <a href="">账户充值</a>
        </li>
        <li>
            <a href="">收支记录</a>
        </li>
        <li>
            <a href="">申请发票</a>
        </li>
        <li>
            <a href="">我的背包</a>
        </li>
    </ul>
</div>
<div>





    <div class="box">
        <div class="form-horizontal">
            <div class="form-group">
                <label class="control-label col-md-2">旧密码</label>
                <div class="col-md-10">
                    <input type="text" class="form-control text-box single-line" name="New_password" id="New_password" onkeydown="keydownEvent(event,1)" />
                    <span class="field-validation-valid text-danger" data-valmsg-for="moneys" data-valmsg-replace="true"></span>
                </div>

            </div>
        </div>
        <div class="form-horizontal">
            <div class="form-group">
                <label class="control-label col-md-2">新密码</label>
                <div class="col-md-10">
                    <input type="text" class="form-control text-box single-line" id="Old_cipher" name="note" onkeydown="keydownEvent(event,2)"  />
                </div>
            </div>
        </div>
        <div class="form-horizontal">
            <div class="form-group">
                <label class="control-label col-md-2">确认密码</label>
                <div class="col-md-10">
                    <input type="text" class="form-control text-box single-line" id="Confirm_the_password" name="note" onkeydown="keydownEvent(event,3)" />
                </div>
            </div>
        </div>
        <div class="form-horizontal">
            <div class="form-group">
                <div class="col-md-10">
                </div>
                <div class="col-md-2">
                    <button type="button" class="btn btn-primary btn-toastr"  onclick="verification_Code()">提交</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

<script src="http://cdn.bootcss.com/blueimp-md5/1.1.0/js/md5.js"></script>

<script>
    Date.prototype.Format = function (fmt) { //author: meizz
        var o = {
            "M+": this.getMonth() + 1,                 //月份
            "d+": this.getDate(),                    //日
            "h+": this.getHours(),                   //小时
            "m+": this.getMinutes(),                 //分
            "s+": this.getSeconds(),                 //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds()             //毫秒
        };
        if (/(y+)/.test(fmt))
            fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }

    ///正则表达式8位
    //    (?!^\\d+$)不能全是数字
    //    (?!^[a-zA-Z]+$)不能全是字母
    //    [a-zA-Z0-9] 可以为数字和字母
    //    .{8,20}长度不能少于8位，大于20位
    var input = $("input[type='text']");
    function keydownEvent(event,id) {
        if(event.keyCode == 9) {
            var values = input[id].value;
            var pwd= /^(?!\d+$)(?![A-Za-z]+$)[a-zA-Z0-9]{8,20}$/;

            if(!pwd.exec(values)){
                return false;
            }

        }
    }
    function verification_Code() {
        var pwd= /^(?!\d+$)(?![A-Za-z]+$)[a-zA-Z0-9]{6,}$/;
        var New_password =$("#New_password").val();
        var Old_cipher =$("#Old_cipher").val();
        var Confirm_the_password =$("#Confirm_the_password").val();
        if(!pwd.exec(New_password)){
            return false;
        }
        if(!pwd.exec(Old_cipher)){
            return false;
        }
        if(!pwd.exec(Confirm_the_password)){
            return false;
        }

        if(Old_cipher ==Confirm_the_password ){
            return false;
        }
        if(New_password == Confirm_the_password){
            return false;
        }
        var id = new Date().Format("hhmmssS");
        var ids = id;
        id = md5(id);
        $.ajax({
            type: "POST",
            data:{"md5":id,"md51":ids,"Old_cipher":Old_cipher,"Confirm_the_password":Confirm_the_password},
            url: "/jsons/modify",
            dataType: "json",
                success: function(data){
                var code = data.code;
                if(code== -1){
                    alert("更改失败！");
                }else if(code == 1){
                    alert("更改成功！");
                }
            }

        });
    }
</script>